#include <iostream>
#include <cstring>
using namespace std;
const int N = 5010 , M = 2e6 + 10 , INF = 0x3f3f3f3f;

int g[N][N];
int dis[N];
bool st[N];
int n , m;

int Prim()
{
    memset(dis,0x3f,sizeof dis);
    int res = 0;
    for(int i = 1 ; i <= n ; ++i)
    {
        int t = -1;
        for(int j = 1 ; j <= n ; ++j)
            if(!st[j] && (t == -1 | dis[j] < dis[t])) t = j;
            
        if(i && t == INF) return INF;
        if(i) res += dis[t];
        for(int j = 1 ; j <= n ; ++j)
            dis[j] = min(dis[j],g[t][j]);
        st[t] = true;
    }
    return res;
}

int main()
{
    scanf("%d%d",&n,&m);
    for(int i = 0 ; i < m ; ++i)
    {
        int a , b , w;
        scanf("%d%d",&a,&b,&w);
        g[a][b] = g[b][a] = min(g[a][b] , w);
    }
    int t = Prim();
    if(t > INF / 2) printf("orz");
    else printf("%d",t);
    return 0;
}